package com.example.springsecurity.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.springsecurity.common.resp.ResponseResult;
import com.example.springsecurity.entity.SystemMenu;
import com.example.springsecurity.service.SystemMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Description：
 * @Author： fengcheng
 * @Date： 2025/1/20 18:01
 */
@Slf4j
@Data
@Tag(name = "共享控制器获取信息")
@RestController
public class CommonController {

    @Resource
    private SystemMenuService systemMenuService;

    /**
     * @Description：校验路由是否存在
     * @Author：fengcheng
     * @Date：2025/1/17 09:54
     * @Param：systemUser
     * @ParamsType：[com.example.springsecurity.entity.SystemUser]
     * @Return：com.example.springsecurity.common.response.ResponseResult<com.example.springsecurity.vo.UserLoginResultVo>
     */
    @Operation(summary = "校验路由是否存在")
    @PostMapping("/route/isRouteExist")
    public ResponseResult<Boolean> login(@RequestBody Map<String, String> map) {
        LambdaQueryWrapper<SystemMenu> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SystemMenu::getRouteName, map.get("routeName"));
        List<SystemMenu> list = systemMenuService.list(queryWrapper);
        return ResponseResult.success(!list.isEmpty());
    }
}
